/*
* Created by: yyf
* Description: 母基金管理--投资中母基金 tab详情编辑
*/
<template>
    <div :class="getClass()">
        <el-row>
            <el-col :span="10" class="ca-title ca-m-b-20">
                <h3>基本信息</h3>
            </el-col>
            <el-col :span="14" class="ca-pull-right ca-align-right" v-if="!isAdd">
                <el-button type="primary" size="medium" @click="save">保存</el-button>
                <el-button size="medium" @click="cancel">取消</el-button>
            </el-col>
        </el-row>
        <el-form label-width="140px" ref="detailForm" :model="fund" :rules="rules">
            <el-row>
                <el-col :span="8">
                    <el-form-item label="基金规模(万元)" prop="fundScale">
                        <el-input v-model="fund.fundScale" :maxlength="17"></el-input>
                    </el-form-item>
                    <el-form-item label="基金类型">
                        <el-select v-model="fund.fundType" placeholder="请选择" class="ca-w-100">
                            <el-option
                                v-for="item in initView.fundType"
                                :label="item.name"
                                :key="item.id"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="董事长">
                        <el-input v-model="fundMother.chairman" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="成立时间">
                        <el-date-picker
                            v-model="fund.establishTime"
                            type="date"
                            placeholder="选择开始日期"
                            class="ca-w-100">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="投资期(年)" prop="investmentPeriod">
                        <el-input v-model="fund.investmentPeriod" :maxlength="10"></el-input>
                    </el-form-item>
                    <el-form-item label="基金类别">
                        <el-select v-model="fund.fundCategory" placeholder="请选择" class="ca-w-100">
                            <el-option
                                v-for="item in initView.fundCategory"
                                :label="item.name"
                                :key="item.id"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="总经理">
                        <el-input v-model="fundMother.generalManager" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="是否备案">
                        <el-select v-model="fundMother.backups" placeholder="请选择" class="ca-w-100">
                            <el-option
                                v-for="item in initView.reference"
                                :label="item.name"
                                :key="item.id"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="7">
                    <el-form-item label="退出期(年)" prop="exitPeriod">
                        <el-input v-model="fund.exitPeriod" :maxlength="10"></el-input>
                    </el-form-item>
                    <el-form-item label="监事会主席">
                        <el-input v-model="fundMother.supervisor" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <csRegion title="注册地点"
                              :address="address"
                              labelWidth="138px"
                               ref="regist">
                    </csRegion>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="16">
                    <el-form-item label="基金管理费(年利率)">
                        <el-input v-model="fundMother.manageFee" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="16">
                    <el-form-item label="基金管理人">
                        <el-input v-model="fundMother.manager" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="16">
                    <el-form-item label="基金托管人">
                        <el-input v-model="fundMother.custodian" :maxlength="100"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="23">
                    <el-form-item label="管理公司">
                        <el-input v-model="fundMother.managementCompany" type="textarea" :row="4" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="基金简介">
                        <el-input v-model="fundMother.brief" type="textarea" :row="4" :maxlength="4000"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script type="text/ecmascript-6">
    //    import { mapActions } from 'vuex';
    //    import {api} from '../api';
    //    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    //    import { isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                itemId: '',
                initView: {
                    fundCategory: [{id: '', name: '请选择'}, ...this.$store.state.user.dictionaryMap.fundCategory],// 基金类别
                    fundType: [{id: '', name: '请选择'}, ...this.$store.state.user.dictionaryMap.fundType],// 基金类型
                    reference: [{id: '', name: '请选择'}, ...this.$store.state.user.dictionaryMap.whether], // 是否备案
                },
                address: {
                    province: '',
                    city: '',
                    district: '',
                    businessType: 1,
                    registrationDetailed: ''
                },
                rules: {
                    investmentPeriod: [
                        { required: true, message: '请输入投资期', trigger: 'blur' },
                        { validator: this.checkIntegerNumber, trigger: 'blur'}
                    ],
                    exitPeriod: [
                        { required: true, message: '请输入退出期', trigger: 'blur' },
                        { validator: this.checkIntegerNumber, trigger: 'blur' }
                    ],
                    fundScale: [
                        { validator: this.validateMoneyNumber, trigger: 'blur' }
                    ],
                },
            };
        },
        props: ['isAdd', 'fund', 'fundMother', 'region'],
        watch: {
            address: {
                handler(val) {
                    this.$emit('changeRegion', val)
                },
                deep: true
            }
        },
        mounted() {
            if (this.region.length > 0) {
                this.address = {
                    province: this.region[0].province,
                    city: this.region[0].city,
                    district: this.region[0].district,
                    businessType: 1,
                    registrationDetailed: this.region[0].registrationDetailed
                };
                this.$refs.regist.inview(this.address)
            }
            if (this.$route.params.itemId) {
                this.itemId = this.$route.params.itemId;
            } else {
                this.itemId = '';
            }
        },
        methods: {
            getClass() {
                if (this.isAdd) {
                    return 'ca-box ca-p-20 ca-m-t-20';
                } else {
                    return ''
                }
            },
            // 保存
            save() {
                let isSave = this.validateAdd();  // 验证通过，可以保存
                if (isSave) {
                    this.$emit('save');
                }
            },
            // 取消,
            cancel() {
                this.$emit('changeEdit', false)
            },
            validateAdd() {
                let isSave = null;
                this.$refs.detailForm.validate((valid) => {
                    if (valid) {
                        isSave = true;
                    } else {
                        isSave = false;
                    }
                })
                return isSave;
            },
        },
        components: {
            'csRegion': require('__components/region/index'), // 注册地点组件
        }
    }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
    .ca-w-100 {
        width: 100%;
    }
</style>
